package com.chance.cc.crawler.development.bootstrap.bitauto;

import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.downloader.HttpPage;
import com.chance.cc.crawler.core.downloader.HttpRequest;
import com.chance.cc.crawler.core.downloader.HttpRequestBody;
import com.chance.cc.crawler.core.downloader.http.HttpClientDownloader;
import com.chance.cc.crawler.core.downloader.http.HttpClientGenerator;
import com.chance.cc.crawler.core.downloader.proxy.SiteConfigProxyProvider;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;
import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName bitauto
 * @Description TODO
 * @Author songding]
 * @Date 2021/11/25 10:46
 * @Version 1.0
 **/
public class Test1 {
    public static void main(String[] args) {
        String domain = "bitauto";
        String site = "YCHao_article";
        String url = "https://hao.yiche.com/";
        CrawlerRequestRecord record = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .httpUrl(url)
                .domain(domain)
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24 * 6, null))
                .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.interaction)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.comment)
                .build();
        record.setNeedWashPage(true);
        record.tagsCreator().bizTags().addSite(site);
        record.tagsCreator().bizTags().addSiteBiz(site);
        record.tagsCreator().bizTags().addDomain(domain);


        DevCrawlerController.builder()
                .triggerInfo(domain, domain, System.currentTimeMillis(), domain)
                .crawlerThreadNum(30)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domain))
                .consoleResultPipeline("kafka")
                .fileResultPipeline("kafka", "F:\\chance_log\\bitauto\\carType\\ychao.log", false)
                .requestRecord(record)
                // .supportRecord(keywordRecord)
                .build("com.chance.cc.crawler.development.scripts.bitauto")
                .start();




    }

    @Test
    public void test(){
        String time = String.valueOf(System.currentTimeMillis());

        String s  = "cid=508&param={pageIndex: 3, pageSize: 10, stageTime: \"2021-11-25 10:40:51\"}DB2560A6EBC65F37A0484295CD4EDD25"+"1637809035999";
        s="cid=601&param={\"pageIndex\":1,\"pageSize\":10,\"stageTime\":\"\"}DB2560A6EBC65F37A0484295CD4EDD251637809295985";
        HttpClientDownloader downloader = new HttpClientDownloader();
        downloader.setClientGenerator(new HttpClientGenerator());
        downloader.setProxyProvider(new SiteConfigProxyProvider());
        HttpConfig httpConfig = HttpConfig.me("bitauto");
        HttpRequest httpRequest = new HttpRequest();
        httpRequest.setResponseCharset("UTF-8");
        httpRequest.setMethod("post");
        httpRequest.setUrl("http://192.168.1.210:8899/encrypt/sign");
        Map<String,Object> bodyMap = new HashMap<>();
        bodyMap.put("params",s);
        HttpRequestBody form = HttpRequestBody.form(bodyMap, "UTF-8");
        httpRequest.setRequestBody(form);
        HttpPage download = downloader.download(httpRequest, httpConfig);
        String rawText = download.getRawText();
        System.out.println(rawText+"----------"+time);
    }

    /*  * 将时间戳转换为时间 */
    @Test
    public  void stampToDate(){
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long lt = new Long(System.currentTimeMillis());
        Date date = new Date(lt);
        res = simpleDateFormat.format(date);
        System.out.println(res);
       // return res;
    }
}


